package com.chaychan.bottombarlayout_ohos.slice;

import com.chaychan.bottombarlayout_ohos.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.dialog.CommonDialog;
import ohos.app.Context;

public class MenuAddDialog extends CommonDialog {
    private Context context;

    public MenuAddDialog(Context context) {
        super(context);
        this.context = context;
        setAutoClosable(true);
        setAlignment(LayoutAlignment.TOP | LayoutAlignment.RIGHT);
    }

    @Override
    protected void onCreate() {
        super.onCreate();


        LayoutScatter scatter = LayoutScatter.getInstance(context);
        Component component = scatter.parse(ResourceTable.Layout_menu_add_dialog, null, false);

        Text addItem = (Text) component.findComponentById(ResourceTable.Id_addItem);
        Text removeItem = (Text) component.findComponentById(ResourceTable.Id_removeItem);
        addItem.setClickedListener(component12 -> {
            if (onMenuSelectedListener != null) {
                onMenuSelectedListener.onMenuSelected(0);
                hide();
            }

        });
        removeItem.setClickedListener(component1 -> {
            if (onMenuSelectedListener != null) {
                onMenuSelectedListener.onMenuSelected(1);
                hide();
            }

        });
        setContentCustomComponent(component);
        setSize(ComponentContainer.LayoutConfig.MATCH_CONTENT, ComponentContainer.LayoutConfig.MATCH_CONTENT);


    }


    private OnMenuSelectedListener onMenuSelectedListener;

    public interface OnMenuSelectedListener {
        void onMenuSelected(int position);
    }

    public void setonMenuSelectedListener(OnMenuSelectedListener onMenuSelectedListener) {
        this.onMenuSelectedListener = onMenuSelectedListener;
    }
}
